package PTA_JAVA.Exception;

import java.util.*;
class IllegalScoreException extends Exception {

    public IllegalScoreException(String score) {
        super(score);
    }
}
class IllegalNameException extends Exception {

    public IllegalNameException(String name) {
        super(name);
    }
}

class Student {
    private String name;
    private String score;

    public String getName() {
        return name;
    }

    public void setName(String name) throws IllegalNameException {
        //如果姓名首字母为数字则抛出IllegalNameException
        if (name.substring(0,1).matches("[0-9]*")) {
            throw new IllegalNameException("the first char of name must not be digit, name="+name);
        } else {
            this.name = name;
        }
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public String addScore(String score) throws IllegalScoreException {
        if (Integer.parseInt(score) < 0 || Integer.parseInt(score) > 100) {
            throw new IllegalScoreException("score out of range, score="+score);
        } else {
            this.score = score;
        }
        return this.score;
    } //如果加分后分数<0 或>100，则抛出IllegalScoreException，加分不成功。

    @Override
    public String toString() {
        return "Student [" +
                "name=" + name  +
                ", score=" + score  +
                ']';
    }
}

class Main{
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Student stu = new Student();
        while(sc.hasNext()){
            String s=sc.nextLine();
            if(s.equals("other")){
                break;
            }else{
                stu = new Student();
                String[] str=sc.nextLine().split(" ");
                if(str.length==2){
                    try{
                        stu.setName(str[0]);
                    }catch (IllegalNameException e){
                        System.out.println(e);
                    }
                    try{
                        stu.addScore(str[1]);
                    }catch (IllegalScoreException e){
                        System.out.println(e);
                    }
                    if(stu.getScore()!=null && stu.getName()!=null){
                        System.out.println(stu);
                    }
                }else{
                    System.out.println("java.util.NoSuchElementException");
                }
            }
        }
        sc.close();
        System.out.println("scanner closed");
    }
}
